<?php
/**
 * Project: AIGC
 * Author: moufer <moufer@163.com>
 * Date: 2024/7/20 10:59
 */

namespace module\chat\front\table;

use module\chat\model\Message;
use mof\front\Table;
use mof\utils\DictArray;
use mof\utils\ElementData;

class MessageTable extends Table
{
    protected string $serverBaseUrl  = '/{module}/admin/{table}';
    protected bool   $showSearch     = false;
    protected array  $toolbarButtons = ['refresh', 'delete', 'search'];

    protected ElementData $typeListEd;

    protected function init(): void
    {
        parent::init();
        $typeList = Message::getTypeList();
        $this->typeListEd = DictArray::make($typeList)->toElementData();

        //tabs
        $this->tabProp = 'object_type';
        $this->tabs = $this->typeListEd->toTabs('label', 'value');
        $this->activeTab = array_keys($typeList)[0];
    }

    protected function columnId(): array
    {
        return [
            "prop"  => 'id',
            "label" => 'ID',
        ];
    }

    protected function columnUserId(): array
    {
        return [
            "prop"   => 'user_id',
            "label"  => '用户ID',
            "search" => true,
        ];
    }

    protected function columnNickname(): array
    {
        return [
            "prop"      => 'user.nickname',
            "propAlias" => "user_id",
            "label"     => '用户昵称'
        ];
    }

    protected function columnObjectType(): array
    {
        return [
            "prop"    => 'object_type',
            "label"   => '类型',
            "search"  => false,
            "visible" => false,
            "type"    => "select",
            "options" => $this->typeListEd->toSelectOptions(),
        ];
    }

    protected function columnObjectName(): array
    {
        return [
            "prop"      => 'object.name',
            "propAlias" => "object_id",
            "label"     => '会话名称',
        ];
    }

    protected function columnPromptText(): array
    {
        return [
            "prop"  => 'prompt_text',
            "label" => '用户输入内容',
            "width" => '*'
        ];
    }

    protected function columnChannelName(): array
    {
        return [
            "prop"      => 'channel.name',
            "propAlias" => "channel_id",
            "label"     => 'AI回复通道',
        ];
    }

    protected function columnTotalTokens(): array
    {
        return [
            "prop"  => 'total_tokens',
            "label" => '总tokens',
        ];
    }

    protected function columnSendAt(): array
    {
        return [
            "prop"   => 'send_at',
            "label"  => '提问时间',
            "type"   => "datetime",
            "search" => [
                "type" => "daterange",
            ]
        ];
    }
}